package cn.fl.audit.service.impl;

import java.util.ArrayList;
import java.util.List;

import cn.fl.preloan.condition.AuditStandingBookQueryCondition;
import cn.fl.project.constant.CarStyleConstant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;

import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.comm.facade.framework.dto.SysDictionaryDTO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.Pager;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.DateUtils;
import cn.cmm.base.framework.utils.DecimalUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.audit.condition.AudGuarPassOpQueryCondition;
import cn.fl.audit.condition.AudPrjPassOpQueryCondition;
import cn.fl.audit.condition.AudStandingBookQueryCondition;
import cn.fl.audit.constant.AudStandingBookConstant;
import cn.fl.audit.dto.AudGuarPassOpDTO;
import cn.fl.audit.dto.AudPrjPassOpDTO;
import cn.fl.audit.service.IAudPrjPassOpService;
import cn.fl.audit.service.IAudReturnVisitService;
import cn.fl.audit.service.IAudStandingBookService;
import cn.fl.audit.service.IAuditApiService;
import cn.fl.audit.transform.AudPrjPassOpVOTransform;
import cn.fl.audit.vo.AudPrjPassOpVO;
import cn.fl.audit.vo.AudReturnVisitVO;
import cn.fl.audit.vo.AudStandingBookVO;
import cn.fl.audit.vo.AudVisitTkVO;
import cn.fl.customer.service.ICstBscInfoService;
import cn.fl.customer.vo.CstBscInfoVO;
import cn.fl.customer.vo.CstNpBscInfoVO;
import cn.fl.customer.vo.CstNpSocialRlVO;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.framework.constant.DictionaryConstant;
import cn.fl.project.condition.PrjPrdBscInfoQueryCondition;
import cn.fl.project.condition.PrjPrdDtlQueryCondition;
import cn.fl.project.condition.PrjQuatPrpsFeeQueryCondition;
import cn.fl.project.condition.PrjQuatPrpsQueryCondition;
import cn.fl.project.constant.PrjQuatPrpsFeeConstant;
import cn.fl.project.service.IPrjBscInfoService;
import cn.fl.project.service.IPrjCstBscInfoService;
import cn.fl.project.service.IPrjPrdBscInfoService;
import cn.fl.project.service.IPrjPrdDtlService;
import cn.fl.project.service.IPrjQuatPrpsFeeService;
import cn.fl.project.service.IPrjQuatPrpsService;
import cn.fl.project.vo.PrjBscInfoVO;
import cn.fl.project.vo.PrjPrdBscInfoVO;
import cn.fl.project.vo.PrjPrdDtlVO;
import cn.fl.project.vo.PrjQuatPrpsFeeVO;
import cn.fl.project.vo.PrjQuatPrpsVO;
import fl.customer.facade.customer.constant.CustomerConstant;

/**
 * @Description: 信审通过意见 客户端服务层接口实现
 * @Description: 业务层方法名称前缀：新增：add* 删除：remove* 修改：modify* 查询对象：select* get* 批量：batch* 查询集合：search*
 */
@Service
public class AudPrjPassOpServiceImpl implements IAudPrjPassOpService {

	/**
	 * 日志
	 */
	private static final Logger logger = LoggerFactory.getLogger(AudPrjPassOpServiceImpl.class);
	
	@Autowired
	private IAuditApiService auditApiService;
	
	/**
	 * 本地数据字典服务
	 */
	@Autowired
	private ISysDictionaryApiService sysDictionaryApiService;
	/**
	 * 项目信息服务
	 */
	@Autowired
	private IPrjBscInfoService prjBscInfoService;
	
	/**
	 * 项目客户信息查询服务
	 */
	@Autowired
	private IPrjCstBscInfoService prjCstBscInfoService;
	
	/**
	 * 客户基础信息服务
	 */
	@Autowired
	private ICstBscInfoService cstBscInfoService;
	
	/**
	 * 项目报价方案信息服务
	 */
	@Autowired
	private IPrjQuatPrpsService prjQuatPrpsService;
	
	/**
	 * 项目费用信息服务
	 */
	@Autowired
	private IPrjQuatPrpsFeeService prjQuatPrpsFeeService;
	
	/**
	 * 项目产品明细服务
	 */
	@Autowired
	private IPrjPrdDtlService prjPrdDtlService;
	
	/**
	 * 项目产品基础服务
	 */
	@Autowired
	private IPrjPrdBscInfoService prjPrdBscInfoService;
	
	/**
	 * 回访信息服务
	 */
	@Autowired
	private IAudReturnVisitService audReturnVisitService;
	
	/**
	 * 台账信息服务
	 */
	@Autowired
	private IAudStandingBookService audStandingBookService;

	@Override
	public AudPrjPassOpVO selectById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			BaseLogUtils.info(logger, "selectById", "主键参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return null;
		}
		AudPrjPassOpDTO dto = null;//this.自定义ApiService.selectById(id);
		return AudPrjPassOpVOTransform.toVO(dto);
	}

	@Override
	public Long add(AudPrjPassOpVO entity) throws BaseException{
		if(null == entity){
			BaseLogUtils.info(logger, "add", "新增对象不能为空!", CurrentThreadContext.getCurrentUserName());
			return null;
		}
		return this.auditApiService.addAudPrjPassOp(AudPrjPassOpVOTransform.toDTO(entity));
	}

	@Override
	public boolean removeById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			BaseLogUtils.info(logger, "removeById", "删除主键参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		}
		//return this.audPrjPassOpApiService.removeById(id);
		return false;
	}
	
	/**
     * 删除
     * @param ids
     * @return
     */
    public boolean removeByIds(List<Long> ids)throws BaseException{
    	if(CollectionUtils.isEmpty(ids)){
    		BaseLogUtils.info(logger, "removeByIds", "删除主键参数集合不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		};
		return false;
    }

	@Override
	public boolean modify(AudPrjPassOpVO entity) throws BaseException{
		if(null == entity || StringUtils.isEmpty(entity.getId())){
			BaseLogUtils.info(logger, "modify", "修改对象参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		}
		return this.auditApiService.modifyAudPrjPassOp(AudPrjPassOpVOTransform.toDTO(entity));
	}

	@Override
	public Pager searchListPage(Pager page) throws BaseException{
		if(null == page)page = new Pager();
		//return this.audPrjPassOpApiService.searchListPage(page);
		return null;
	}
	
	//******************************************私有方法*********************************/
	/**
	 * 根据字典中代码组值获取组员集合
	 * @param grpCd 代码组值
	 * @return 集合
	 */
	private List<KeyValueVO> getKvList(String grpCd){
		List<KeyValueVO> kvList = new ArrayList<>();
		try {
			List<SysDictionaryDTO> sysDictionaryDTOList = this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), grpCd);
			if(CollectionUtils.isNotEmpty(sysDictionaryDTOList)){
				for (SysDictionaryDTO sysDictionaryDTO : sysDictionaryDTOList) {
					KeyValueVO keyValueVO = new KeyValueVO();
					keyValueVO.setKey(sysDictionaryDTO.getCode());
					keyValueVO.setValue(sysDictionaryDTO.getCodeNm());
					kvList.add(keyValueVO);
				}
			}
		} catch (BaseException e) {
			BaseLogUtils.info(logger, "getKvList", "获取字典项组"+grpCd+"失败.ERROR:"+e.getMessage(), CurrentThreadContext.getCurrentUserName());
		} catch (Exception e) {
			BaseLogUtils.error(logger, "getKvList", "获取字典项组"+grpCd+"失败,系统错误.ERROR:"+e.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return kvList;
	}
	
	@Override
	public List<KeyValueVO> searchPolicyStandatrdsCdList() throws BaseException {
		return this.getKvList(DictionaryConstant.CODE_AUD_POLICY_STANDATRDS_CD);
	}

	@Override
	public List<KeyValueVO> searchStandardCdList() throws BaseException {
		return this.getKvList(DictionaryConstant.CODE_AUD_STANDARD_CD);
	}

	@Override
	public List<KeyValueVO> searchExecuteTemplateCdList() throws BaseException {
		return this.getKvList(DictionaryConstant.CODE_AUD_EXECUTE_TEMPLATE_CD);
	}

	@Override
	public List<KeyValueVO> searchBuyCdList() throws BaseException {
		return this.getKvList(DictionaryConstant.CODE_AUD_BUY_CD);
	}

	@Override
	public List<KeyValueVO> searchLesseeAssetsCdList() throws BaseException {
		return this.getKvList(DictionaryConstant.CODE_AUD_ASSETS_CD);
	}

	@Override
	public List<KeyValueVO> searchCarConfigCdList() throws BaseException {
		return this.getKvList(DictionaryConstant.CODE_AUD_RELIZE_STATE_CD);
	}

	@Override
	public List<KeyValueVO> searchFinancePlanCdList() throws BaseException {
		return this.getKvList(DictionaryConstant.CODE_AUD_RELIZE_STATE_CD);
	}

	@Override
	public List<KeyValueVO> searchOperationSituationCdList()
			throws BaseException {
		return this.getKvList(DictionaryConstant.CODE_AUD_RELIZE_STATE_CD);
	}

	@Override
	public List<KeyValueVO> searchOperationExperienceCdList()
			throws BaseException {
		return this.getKvList(DictionaryConstant.CODE_AUD_OPERATION_EXPERIENCE_CD);
	}

	@Override
	public List<KeyValueVO> searchPaymentSourceCdList() throws BaseException {
		return this.getKvList(DictionaryConstant.CODE_AUD_OPERATION_EXPERIENCE_CD);
	}

	@Override
	public List<KeyValueVO> searchFulfilCdList() throws BaseException {
		return this.getKvList(DictionaryConstant.CODE_AUD_FULFIL_CD);
	}

	@Override
	public List<KeyValueVO> searchAttitudeCdList() throws BaseException {
		return this.getKvList(DictionaryConstant.CODE_AUD_ASSETS_CD);
	}

	@Override
	public List<KeyValueVO> searchManeuverabilityCdList() throws BaseException {
		return this.getKvList(DictionaryConstant.CODE_AUD_PROCESS_OPINION_CD);
	}

	@Override
	public List<KeyValueVO> searchAssetsProveCdList() throws BaseException {
		return this.getKvList(DictionaryConstant.CODE_AUD_ASSETS_PROVE_CD);
	}

	@Override
	public List<KeyValueVO> searchRelationshipCdList() throws BaseException {
		return this.getKvList(DictionaryConstant.CODE_GRP_RL_TYP_CD);
	}

	@Override
	public AudPrjPassOpVO selectAudPrjPassOpVOByQc(AudPrjPassOpQueryCondition qc) throws BaseException {
		AudPrjPassOpVO audPrjPassOpVO = new AudPrjPassOpVO();
		if(null==qc || null==qc.getProjectId() || StringUtils.isEmpty(qc.getProIntId())){
			return audPrjPassOpVO;
		}
		List<AudPrjPassOpDTO> audPrjPassOpDTOList = this.auditApiService.searchAudPrjPassOpList(qc, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
		if(null!=audPrjPassOpDTOList && CollectionUtils.isNotEmpty(audPrjPassOpDTOList)){
			AudPrjPassOpDTO audPrjPassOpDTO = audPrjPassOpDTOList.get(0);
			if(null!=audPrjPassOpDTO) audPrjPassOpVO = AudPrjPassOpVOTransform.toVO(audPrjPassOpDTO);
		}
		return audPrjPassOpVO;
	}

	/**
	 * 信审通过意见预览
	 */
	@Override
	public String getPreviewString(Long id) throws BaseException {
		if(StringUtils.isEmpty(id)){
			BaseLogUtils.info(logger, "getPreviewString", "预览信审通过意见,主键ID为空.DATA:"+id);
			return "";
		}
		AudPrjPassOpQueryCondition opQC = new AudPrjPassOpQueryCondition();
		opQC.setId(id);
		List<AudPrjPassOpDTO> audPrjPassOpDTOList = this.auditApiService.searchAudPrjPassOpList(opQC, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
		if(CollectionUtils.isNotEmpty(audPrjPassOpDTOList)){
			AudPrjPassOpDTO audPrjPassOpDTO = audPrjPassOpDTOList.get(0);/**信审通过意见audPrjPassOpDTO*/
			if(null==audPrjPassOpDTO){
				BaseLogUtils.info(logger, "getPreviewString", "===信审通过意见audPrjPassOpDTO为NULL===QueryCondition:"+JSON.toJSONString(opQC));
				return "";
			}
			AudGuarPassOpQueryCondition guarQC = new AudGuarPassOpQueryCondition();
			guarQC.setOpId(id);
			/**担保人通过意见audGuarPassOpDTOList*/
			List<AudGuarPassOpDTO> audGuarPassOpDTOList = this.auditApiService.searchAudGuarPassOpList(guarQC,CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd());
			
			Long projectId = audPrjPassOpDTO.getProjectId();
			PrjBscInfoVO prjBscInfoVO = new PrjBscInfoVO();
			PrjQuatPrpsVO prjQuatPrpsVO = new PrjQuatPrpsVO();
			List<PrjQuatPrpsFeeVO> feeList = new ArrayList<PrjQuatPrpsFeeVO>();
			if(StringUtils.isNotEmpty(projectId)){
				prjBscInfoVO = this.prjBscInfoService.selectById(projectId);/**项目信息*/
				PrjQuatPrpsQueryCondition quatQC = new PrjQuatPrpsQueryCondition();
				quatQC.setIsFormalPrps(BaseConstant.IS_YESNO_YES);
				quatQC.setPrjId(projectId);
				List<PrjQuatPrpsVO> quatList = this.prjQuatPrpsService.searchList(quatQC);
				if(CollectionUtils.isNotEmpty(quatList)){
					prjQuatPrpsVO = quatList.get(0);/**项目报价方案信息*/
					if(null!=prjQuatPrpsVO && null!=prjQuatPrpsVO.getId()){
						PrjQuatPrpsFeeQueryCondition feeQc = new PrjQuatPrpsFeeQueryCondition();
						feeQc.setPrpsId(prjQuatPrpsVO.getId());
						feeList = this.prjQuatPrpsFeeService.searchList(feeQc);/**报价方案费用项信息*/
					}else{
						BaseLogUtils.info(logger, "getPreviewString", "===项目报价信息prjQuatPrpsVO为NULL===");
						prjQuatPrpsVO = new PrjQuatPrpsVO();
					}
				}
			}
			Long cstId = null;
			if(null!=prjBscInfoVO){
				cstId = prjBscInfoVO.getCstId();
			}
			CstBscInfoVO cstBscInfoVO = new CstBscInfoVO();
			CstNpBscInfoVO cstNpBscInfoVO = new CstNpBscInfoVO();
			//CstCorpBscInfoVO cstCorpBscInfoVO = new CstCorpBscInfoVO();
			CstNpSocialRlVO cstNpSocialRlVO = new CstNpSocialRlVO();
			if(StringUtils.isNotEmpty(cstId)){
				cstBscInfoVO = this.cstBscInfoService.selectDetailById(cstId);/**承租人信息*/
				if(null!=cstBscInfoVO){
					cstNpBscInfoVO = cstBscInfoVO.getCstNpBscInfoVO();/**承租人为自然人,其他信息*/
					if(null!=cstNpBscInfoVO){
						cstNpSocialRlVO = cstNpBscInfoVO.getCstNpSocialRlVO();/**承租人为自然人,配偶信息*/
					}
					//cstCorpBscInfoVO = cstBscInfoVO.getCstCorpBscInfoVO();/**承租人为法人,其他信息*/
				}
			}
			StringBuffer previewString = new StringBuffer();
			previewString.append("一：信审资料及承租人资质</br>");
			/**判断承租人类型*/
			if(null!=cstBscInfoVO && CustomerConstant.CST_TYP_CD_NP.equals(cstBscInfoVO.getCstTypCd())){	//自然人
				if(null==cstNpBscInfoVO){
					BaseLogUtils.info(logger, "getPreviewString", "===自然人承租人其他信息cstNpBscInfoVO为NULL===");
					cstNpBscInfoVO = new CstNpBscInfoVO();
				}
				if(null==cstNpSocialRlVO){
					BaseLogUtils.info(logger, "getPreviewString", "===自然人承租人配偶信息cstNpSocialRlVO为NULL===");
					cstNpSocialRlVO = new CstNpSocialRlVO();
				}
				previewString.append("&nbsp;&nbsp;&nbsp;1、承租人");
				if(StringUtils.isNotEmpty(cstBscInfoVO.getCstNm())){
					previewString.append(cstBscInfoVO.getCstNm());
					if(StringUtils.isNotEmpty(cstNpBscInfoVO.getMarStsCdNm())){
						previewString.append(cstNpBscInfoVO.getMarStsCdNm());
					}
					previewString.append("，");
				}
				if(StringUtils.isNotEmpty(cstNpSocialRlVO.getRlNm())){
					previewString.append(cstNpSocialRlVO.getRlNm()+"，");
				}
				
				if(StringUtils.isNotEmpty(audPrjPassOpDTO.getCreditInfo())){
					previewString.append("提供的信审资料"+audPrjPassOpDTO.getCreditInfo()+"；</br>");
				}else{
					previewString.append("提供的信审资料真实齐全合规；</br>");
				}
				previewString.append("&nbsp;&nbsp;&nbsp;2、承租人"+cstNpBscInfoVO.getMarStsCdNm()+"，");
				if(StringUtils.isNotEmpty(audPrjPassOpDTO.getQualificationsInfo())){
					previewString.append("资质"+audPrjPassOpDTO.getQualificationsInfo()+"，");
				}else{
					previewString.append("资质合规，");
				}
				if(StringUtils.isNotEmpty(audPrjPassOpDTO.getAssetsProveCdNm())){
					previewString.append("提供"+audPrjPassOpDTO.getAssetsProveCdNm()+"作为资产证明，");
				}else{
					previewString.append("未提供资产证明，");
				}
				if(StringUtils.isNotEmpty(audPrjPassOpDTO.getResearchReport())){
					previewString.append("调查报告显示"+audPrjPassOpDTO.getResearchReport()+"；</br>");
				}
				else{
					previewString.append("</br>");
				}
			}else{	//法人
				if(null==cstBscInfoVO)cstBscInfoVO = new CstBscInfoVO();
				previewString.append("&nbsp;&nbsp;&nbsp;1、承租人"+cstBscInfoVO.getCstNm()+"，");
				if(StringUtils.isNotEmpty(audPrjPassOpDTO.getCreditInfo())){
					previewString.append("提供的信审资料"+audPrjPassOpDTO.getCreditInfo()+"；</br>");
				}else{
					previewString.append("提供的信审资料真实齐全合规；</br>");
				}
				previewString.append("&nbsp;&nbsp;&nbsp;2、承租人");
				if(null!=audPrjPassOpDTO.getRegisterTm()){
					previewString.append("注册时间为"+DateUtils.formatDateToString(audPrjPassOpDTO.getRegisterTm(), DateUtils.YYYY_MM_DD)+"，");
				}
				if(StringUtils.isNotEmpty(audPrjPassOpDTO.getBizInfo())){
					previewString.append("主要从事业务"+audPrjPassOpDTO.getBizInfo()+"，");
				}
				if(StringUtils.isNotEmpty(audPrjPassOpDTO.getQualificationsInfo())){
					previewString.append("资质"+audPrjPassOpDTO.getQualificationsInfo()+"，");
				}else{
					previewString.append("资质合规，");
				}
				if(StringUtils.isNotEmpty(audPrjPassOpDTO.getAssetsProveCdNm())){
					previewString.append("提供"+audPrjPassOpDTO.getAssetsProveCdNm()+"作为资产证明");
				}else{
					previewString.append("未提供资产证明");
				}
				if(StringUtils.isNotEmpty(audPrjPassOpDTO.getResearchReport())){
					previewString.append("，调查报告显示"+audPrjPassOpDTO.getResearchReport()+"；</br>");
				}else{
					previewString.append("；</br>");
				}
			}
			//=========================================================================================
			if(CollectionUtils.isNotEmpty(audGuarPassOpDTOList)){
				previewString.append("&nbsp;&nbsp;&nbsp;3、");
				boolean isFirst = true;
				for (AudGuarPassOpDTO audGuarPassOpDTO : audGuarPassOpDTOList) {
					if(null!=audGuarPassOpDTO){
						if(!isFirst){
							previewString.append("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
						}
						previewString.append("担保人"+audGuarPassOpDTO.getGuarNm());
						if(StringUtils.isNotEmpty(audGuarPassOpDTO.getRelationshipCdNm())){
							previewString.append("与承租人关系"+audGuarPassOpDTO.getRelationshipCdNm()+"，");
						}
						if(StringUtils.isNotEmpty(audGuarPassOpDTO.getCreditInfo())){
							previewString.append("提供的信审资料"+audGuarPassOpDTO.getCreditInfo()+"；");
						}else{
							previewString.append("提供的信审资料真实齐全合规；");
						}
						if(StringUtils.isNotEmpty(audGuarPassOpDTO.getQualificationsInfo())){
							previewString.append("资质"+audGuarPassOpDTO.getQualificationsInfo()+"，");
						}else{
							previewString.append("资质合规，");
						}
						if(StringUtils.isNotEmpty(audGuarPassOpDTO.getAssetsProveCdNm())){
							previewString.append("提供"+audGuarPassOpDTO.getAssetsProveCdNm()+"作为资产证明");
						}else{
							previewString.append("未提供资产证明");
						}
						if(StringUtils.isNotEmpty(audGuarPassOpDTO.getResearchReport())){
							previewString.append("，调查报告显示"+audGuarPassOpDTO.getResearchReport()+"；</br>");
						}else{
							previewString.append("；</br>");
						}
						isFirst = false;
					}
				}
				previewString.append("&nbsp;&nbsp;&nbsp;4、");
			}else{
				BaseLogUtils.info(logger, "", "===担保人通过意见audGuarPassOpDTOList为空===");
				previewString.append("&nbsp;&nbsp;&nbsp;3、");
			}
			//==========================================================================================
			if(StringUtils.isNotEmpty(audPrjPassOpDTO.getTimes())){
				previewString.append("此次为第（"+audPrjPassOpDTO.getTimes()+"）次在我司融资，");
			}else{
				previewString.append("此次为第（0）次在我司融资，");
			}
			if(StringUtils.isNotEmpty(audPrjPassOpDTO.getBadRecordInfo())){
				previewString.append("不良信用记录"+audPrjPassOpDTO.getBadRecordInfo()+"，");
			}else{
				previewString.append("无不良信用记录，");
			}
			if(StringUtils.isNotEmpty(audPrjPassOpDTO.getCourtsEnforceInfo())){
				previewString.append("法院执行情况"+audPrjPassOpDTO.getCourtsEnforceInfo()+";");
			}else{
				previewString.append("无法院执行情况；");
			}
			//===========================================================================================
			previewString.append("</br>二：产品政策</br>&nbsp;&nbsp;&nbsp;");
			/**判断模板*/
			if(StringUtils.isNotEmpty(audPrjPassOpDTO.getExecuteTemplateCd())){
				if(null==prjBscInfoVO){
					BaseLogUtils.info(logger, "getPreviewString", "===项目信息prjBscInfoVO为NULL===");
					prjBscInfoVO = new PrjBscInfoVO();
				}
				if("1".equals(audPrjPassOpDTO.getExecuteTemplateCd())){	//模板一
					previewString.append(prjBscInfoVO.getBuOrgCdNm()+"业务，代理商类型为"+prjBscInfoVO.getAgntTypCdNm()+"，业务类型为"+prjBscInfoVO.getBizTypCdNm()+"，");
					previewString.append("项目类型为"+prjBscInfoVO.getPrjTypCdNm()+"，业务来源为"+prjBscInfoVO.getBizResCdNm()+"，");
					previewString.append("融资期限（"+prjQuatPrpsVO.getLsPd()+"）"+prjQuatPrpsVO.getLsPdUntCdNm()+"，");
					previewString.append("月还款（"+DecimalUtils.div(prjQuatPrpsVO.getEachEstRntAmt(), 100)+"），");
					previewString.append("收益率（"+audPrjPassOpDTO.getReturnPct()+"），");
					previewString.append("执行政策标准"+audPrjPassOpDTO.getPolicyStandatrdsCdNm());
					if(StringUtils.isNotEmpty(audPrjPassOpDTO.getStandardCdNm())){
						previewString.append("，"+audPrjPassOpDTO.getStandardCdNm()+"。");
					}else{
						previewString.append("。");
					}
				}else{//模板二
					previewString.append(prjBscInfoVO.getBuOrgCdNm()+"业务，代理商类型为"+prjBscInfoVO.getAgntTypCdNm()+"，业务类型为"+prjBscInfoVO.getBizTypCdNm()+"，");
					previewString.append("项目类型为"+prjBscInfoVO.getPrjTypCdNm()+"，业务来源为"+prjBscInfoVO.getBizResCdNm()+"，");
					previewString.append("融资方案为"+prjQuatPrpsVO.getPrpsCfgNm()+"，融资期限为"+prjQuatPrpsVO.getLsPd()+prjQuatPrpsVO.getLsPdUntCdNm());
					if(CollectionUtils.isNotEmpty(feeList)){
						for (PrjQuatPrpsFeeVO prjQuatPrpsFeeVO : feeList) {
							if(prjQuatPrpsFeeVO.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.PRJ_FEE_TYP_CONSULT_1)){//咨询费1
								previewString.append("咨询费1"+DecimalUtils.div(prjQuatPrpsFeeVO.getFeeAmt(), 100)+"，");
							}else if(prjQuatPrpsFeeVO.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.PRJ_FEE_TYP_CONSULT_2)){//咨询费2
								previewString.append("咨询费2"+DecimalUtils.div(prjQuatPrpsFeeVO.getFeeAmt(), 100)+"，");
							}else if(prjQuatPrpsFeeVO.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.PRJ_FEE_TYP_PURCHASE)){//留购价
								previewString.append("留购价"+DecimalUtils.div(prjQuatPrpsFeeVO.getFeeAmt(), 100)+"，");
							}
						}
					}
					previewString.append("年利率"+prjQuatPrpsVO.getAnnIntRatePct()+"，");
					previewString.append("月还款"+DecimalUtils.div(prjQuatPrpsVO.getEachEstRntAmt(), 100)+"，");
					previewString.append("收益率"+audPrjPassOpDTO.getReturnPct()+"，");
					previewString.append("执行政策标准"+audPrjPassOpDTO.getPolicyStandatrdsCdNm());
					if(StringUtils.isNotEmpty(audPrjPassOpDTO.getStandardCdNm())){
						previewString.append("，"+audPrjPassOpDTO.getStandardCdNm()+"。");
					}else{
						previewString.append("。");
					}
				}
			}
			//===========================================================================================
			PrjPrdDtlQueryCondition prjPrdDtlQC = new PrjPrdDtlQueryCondition();
			prjPrdDtlQC.setPrjId(projectId);
			List<PrjPrdDtlVO> prjPrdDtlVOList = this.prjPrdDtlService.selectList(prjPrdDtlQC);/**项目产品明细列表*/
			previewString.append("</br>三：上户</br>&nbsp;&nbsp;&nbsp;");
			List<String> companyNmList = new ArrayList<String>();
			String companyNmString = "";
			if(CollectionUtils.isNotEmpty(prjPrdDtlVOList)){
				for (PrjPrdDtlVO prjPrdDtlVO : prjPrdDtlVOList) {
					if(null!=prjPrdDtlVO && !companyNmList.contains(prjPrdDtlVO.getLnkCompNm()) && null!=prjPrdDtlVO.getLnkCompNm()){
						companyNmList.add(prjPrdDtlVO.getLnkCompNm());
					}
				}
				if(CollectionUtils.isNotEmpty(companyNmList)){
					for (String string : companyNmList) {
						companyNmString+=string;
						companyNmString+="，";
					}
					previewString.append("上公司户,挂靠公司为"+companyNmString);
				}else{
					previewString.append("非挂靠，上个人户");
				}
			}else{
				BaseLogUtils.info(logger, "getPreviewString", "===项目产品明细信息prjPrdDtlVOList为空===");
			}
			//===========================================================================
			PrjPrdBscInfoQueryCondition prjPrdBscQC = new PrjPrdBscInfoQueryCondition();
			prjPrdBscQC.setPrjId(projectId);
			List<PrjPrdBscInfoVO> prjPrdBscInfoVOList = this.prjPrdBscInfoService.searchList(prjPrdBscQC);
			previewString.append("</br>四：核价</br>&nbsp;&nbsp;&nbsp;");
			previewString.append("1、融资数量为");
			if(CollectionUtils.isNotEmpty(prjPrdBscInfoVOList)){
				int mainQty = 0;
				int handQty = 0;
				for (PrjPrdBscInfoVO prjPrdBscInfoVO : prjPrdBscInfoVOList) {
					if(null!=prjPrdBscInfoVO){
						//previewString.append(prjPrdBscInfoVO.getPrdQty()+prjPrdBscInfoVO.getPrdNm()+"，");
						if(StringUtils.isNotEmpty(prjPrdBscInfoVO.getPrdQty())){
							/**判断产品类型*/
							String prdTypCd = prjPrdBscInfoVO.getPrdTypCd();
							Integer prdQty = prjPrdBscInfoVO.getPrdQty();
							if(StringUtils.isNotBlank(prdTypCd)){
								if(prdTypCd.equals(CarStyleConstant.PRD_TYPE_9)){
									handQty+=prdQty;
								}
							}else{
								mainQty+=prdQty;
							}
						}
					}
				}
				previewString.append(mainQty+"主"+handQty+"挂，");
			}
			previewString.append("合同总额"+prjQuatPrpsVO.getContAmt()+"，");
			//查询核价基础台账信息
			previewString.append("</br>&nbsp;&nbsp;&nbsp;2、");
			if(null!=audPrjPassOpDTO){
				Long prjId = audPrjPassOpDTO.getProjectId();//项目ID
				String proIntId = audPrjPassOpDTO.getProIntId();//流程实例ID
				if(CollectionUtils.isNotEmpty(prjPrdBscInfoVOList)){
					for (PrjPrdBscInfoVO prjPrdBscInfoVO : prjPrdBscInfoVOList) {
						if(null!=prjPrdBscInfoVO){
							Long prjPrdId = prjPrdBscInfoVO.getId();//项目产品ID
							AuditStandingBookQueryCondition bookQC = new AuditStandingBookQueryCondition();
							List<Long> prjIdList = new ArrayList<Long>();
							prjIdList.add(prjId);
							bookQC.setProjectIdList(prjIdList);
							bookQC.setBookTypeCd(AudStandingBookConstant.AUD_TYP_CD_PRCE);//设置台账类型查询条件
							bookQC.setProIntId(proIntId);
							bookQC.setPrjPrdId(prjPrdId);
							AudStandingBookVO audStandingBookVO = this.audStandingBookService.selectAudStandingBookByQc(bookQC);
							if(null!=audStandingBookVO && StringUtils.isNotEmpty(audStandingBookVO.getPricingInfo())){
								previewString.append(audStandingBookVO.getPricingInfo()+"</br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
							}
						}
					}
				}
			}
			
			//===========================================================================
			previewString.append("</br>五：运营分析</br>&nbsp;&nbsp;&nbsp;");
			if(StringUtils.isNotEmpty(audPrjPassOpDTO.getOperationAnalysis())){
				previewString.append(audPrjPassOpDTO.getOperationAnalysis());
			}
			//===========================================================================
			previewString.append("</br>六：电话回访链接</br>&nbsp;&nbsp;&nbsp;");
			previewString.append("<a href=\"javascript:toReturnVisitAddPage();\" class=\"link\">"
				+ "/audit/audReturnVisit/toAddPage.do?isDetail=1&projectId="+audPrjPassOpDTO.getProjectId()+"&proIntId="+audPrjPassOpDTO.getProIntId()
				+"</a>");
			//===========================================================================
			previewString.append("</br>七：信审员评价</br>&nbsp;&nbsp;&nbsp;");
			previewString.append("1、意愿：");
			if(StringUtils.isNotEmpty(audPrjPassOpDTO.getBuyCdNm())){
				previewString.append("承租人购车行为"+audPrjPassOpDTO.getBuyCdNm()+"，");
			}
			if(StringUtils.isNotEmpty(audPrjPassOpDTO.getAttitudeCdNm())){
				previewString.append("回访态度"+audPrjPassOpDTO.getAttitudeCdNm()+"。");
			}
			previewString.append("</br>&nbsp;&nbsp;&nbsp;");
			if(null!=cstBscInfoVO && CustomerConstant.CST_TYP_CD_NP.equals(cstBscInfoVO.getCstTypCd())){	//自然人
				previewString.append("2、家庭资产状况：");
				if(StringUtils.isNotEmpty(audPrjPassOpDTO.getLesseeAssetsCdNm())){
					previewString.append("从提供资产情况来看，承租人资产实力"+audPrjPassOpDTO.getLesseeAssetsCdNm());
				}
			}else{
				previewString.append("2、公司经营状况：");
				if(StringUtils.isNotEmpty(audPrjPassOpDTO.getManagementSituation())){
					previewString.append("从提供财务报表来看，承租人经营状况"+audPrjPassOpDTO.getManagementSituation());
				}
				if(CollectionUtils.isNotEmpty(audGuarPassOpDTOList)){
					for (AudGuarPassOpDTO audGuarPassOpDTO : audGuarPassOpDTOList) {
						if(null!=audGuarPassOpDTO && StringUtils.isNotEmpty(audGuarPassOpDTO.getGuarantorAssetsCdNm())){
							previewString.append("，担保人"+audGuarPassOpDTO.getGuarNm()+"资产实力"+audGuarPassOpDTO.getGuarantorAssetsCdNm());
						}
					}
				}
			}
			previewString.append("</br>&nbsp;&nbsp;&nbsp;");
			previewString.append("3、电话回访反馈：");
			if(StringUtils.isNotEmpty(audPrjPassOpDTO.getCarConfigCdNm())
					||StringUtils.isNotEmpty(audPrjPassOpDTO.getFinancePlanCdNm())
					||StringUtils.isNotEmpty(audPrjPassOpDTO.getOperationSituationCdNm())
					||StringUtils.isNotEmpty(audPrjPassOpDTO.getOperationExperienceCdNm())
					||StringUtils.isNotEmpty(audPrjPassOpDTO.getPaymentSourceCdNm())){
				previewString.append("承租人");
			}
			if(StringUtils.isNotEmpty(audPrjPassOpDTO.getCarConfigCdNm())){
				previewString.append(audPrjPassOpDTO.getCarConfigCdNm()+"车辆配置，");
			}
			if(StringUtils.isNotEmpty(audPrjPassOpDTO.getFinancePlanCdNm())){
				previewString.append(audPrjPassOpDTO.getFinancePlanCdNm()+"融资方案，");
			}
			if(StringUtils.isNotEmpty(audPrjPassOpDTO.getOperationSituationCdNm())){
				previewString.append("对车辆运营情况"+audPrjPassOpDTO.getOperationSituationCdNm()+"，");
			}
			if(StringUtils.isNotEmpty(audPrjPassOpDTO.getOperationExperienceCdNm())){
				previewString.append(audPrjPassOpDTO.getOperationExperienceCdNm()+"运营经验，");
			}
			if(StringUtils.isNotEmpty(audPrjPassOpDTO.getPaymentSourceCdNm())){
				previewString.append(audPrjPassOpDTO.getPaymentSourceCdNm()+"第二还款来源。");
			}
			previewString.append("</br>&nbsp;&nbsp;&nbsp;");
			previewString.append("4、风险:");
			if(StringUtils.isNotEmpty(audPrjPassOpDTO.getRiskAnalysis())){
				previewString.append(audPrjPassOpDTO.getRiskAnalysis());
			}
			previewString.append("</br>&nbsp;&nbsp;&nbsp;");
			previewString.append("5、可操作性评价：");
			if(StringUtils.isNotEmpty(audPrjPassOpDTO.getManeuverabilityCdNm())){
				previewString.append(audPrjPassOpDTO.getManeuverabilityCdNm());
			}
			previewString.append("</br>");
			previewString.append("备注:</br>&nbsp;&nbsp;&nbsp;");
			if(StringUtils.isNotEmpty(audPrjPassOpDTO.getOtherInfo())){
				previewString.append(audPrjPassOpDTO.getOtherInfo());
			}
			return previewString.toString();
		}else{
			BaseLogUtils.info(logger, "getPreviewString", "===信审通过意见audPrjPassOpDTOList为NULL===QueryCondition:"+JSON.toJSONString(opQC));
			return "";
		}
	}

	@Override
	public String getPreviewoperationAnalysis(Long projectId, String proIntId) throws BaseException {
		if(StringUtils.isEmpty(projectId)){
			return "";
		}
		AudReturnVisitVO audReturnVisitVO = this.audReturnVisitService.selectByProjectIdAndProIntId(projectId);
		StringBuffer previewString = new StringBuffer("");
		if(null!=audReturnVisitVO){
			AudVisitTkVO audVisitTkVO = audReturnVisitVO.getAudVisitTkVO();
			if(null!=audVisitTkVO){
				String profitCd = audVisitTkVO.getProfitCd();
				if(AudStandingBookConstant.AUD_PROFIT_CD_SELF.equals(profitCd)){//自用
					previewString.append("承租人");
					if(StringUtils.isNotEmpty(audVisitTkVO.getCmpDesc())){//主营公司介绍
						previewString.append(audVisitTkVO.getCmpDesc()+"，");
					}else{
						previewString.append("  ，");
					}
					previewString.append("主营经营");
					if(StringUtils.isNotEmpty(audVisitTkVO.getBiz())){//经营
						previewString.append(audVisitTkVO.getBiz()+"，");
					}else{
						previewString.append("  ，");
					}
					previewString.append("经营期限为");
					if(StringUtils.isNotEmpty(audVisitTkVO.getBizExp())){//经营期限
						previewString.append(audVisitTkVO.getBizExp()+"。");
					}else{
						previewString.append("  。");
					}
					previewString.append("承租人");
					if(StringUtils.isNotEmpty(audVisitTkVO.getSelfTkDesc())){//自有车辆情况及运输经验
						previewString.append(audVisitTkVO.getSelfTkDesc()+"，");
					}else{
						previewString.append("  ，");
					}
					previewString.append("车辆主要用于");
					if(StringUtils.isNotEmpty(audVisitTkVO.getTkUseDesc())){//车辆用途
						previewString.append(audVisitTkVO.getTkUseDesc()+"，");
					}else{
						previewString.append("  ，");
					}
					previewString.append("运输范围为");
					if(StringUtils.isNotEmpty(audVisitTkVO.getTransRange())){//运输范围
						previewString.append(audVisitTkVO.getTransRange()+"，");
					}else{
						previewString.append("  。");
					}
					previewString.append("该公司收入情况:");
					if(StringUtils.isNotEmpty(audVisitTkVO.getIncome())){//公司收入情况
						previewString.append(audVisitTkVO.getIncome()+"。");
					}else{
						previewString.append("  。");
					}
				}else{//运营
					previewString.append("承租人");
					if(StringUtils.isNotEmpty(audVisitTkVO.getSelfTkDesc())){//自有车辆情况及运输经验
						previewString.append(audVisitTkVO.getSelfTkDesc()+"，");
					}else{
						previewString.append("  ，");
					}
					previewString.append("所购车辆主要用于运输");
					if(StringUtils.isNotEmpty(audVisitTkVO.getGoods())){//主货物
						previewString.append(audVisitTkVO.getGoods()+"，");
					}else{
						previewString.append("  ，");
					}
					previewString.append("运输路线为");
					if(StringUtils.isNotEmpty(audVisitTkVO.getRoute())){//运输路线
						previewString.append(audVisitTkVO.getRoute()+"，");
					}else{
						previewString.append("  ，");
					}
					previewString.append("货物来源为");
					if(StringUtils.isNotEmpty(audVisitTkVO.getToGdsRes())){//去程货物来源
						previewString.append(audVisitTkVO.getToGdsRes()+"，");
					}else{
						previewString.append("  ，");
					}
					previewString.append("去程货物为");
					if(StringUtils.isNotEmpty(audVisitTkVO.getToGds())){//去程货物
						previewString.append(audVisitTkVO.getToGds()+"，");
					}else{
						previewString.append("  ，");
					}
					previewString.append("计费及结算方式为");
					if(StringUtils.isNotEmpty(audVisitTkVO.getToStlWay())){//去程计费及结算方式
						previewString.append(audVisitTkVO.getToStlWay()+"；");
					}else{
						previewString.append("  ；");
					}
					previewString.append("返程货物为");
					if(StringUtils.isNotEmpty(audVisitTkVO.getCmGds())){//返程货物
						previewString.append(audVisitTkVO.getCmGds()+"，");
					}else{
						previewString.append("  ，");
					}
					previewString.append("货物来源于");
					if(StringUtils.isNotEmpty(audVisitTkVO.getCmGdsRes())){//返程货物来源
						previewString.append(audVisitTkVO.getCmGdsRes()+"，");
					}else{
						previewString.append("  ，");
					}
					previewString.append("计费及结算方式为");
					if(StringUtils.isNotEmpty(audVisitTkVO.getCmStlWay())){//返程计费及结算方式
						previewString.append(audVisitTkVO.getCmStlWay()+"；");
					}else{
						previewString.append("  ；");
					}
					previewString.append("驾驶员");
					if(StringUtils.isNotEmpty(audVisitTkVO.getDriver())){//驾驶员
						previewString.append(audVisitTkVO.getDriver()+"，");
					}else{
						previewString.append("  ，");
					}
					previewString.append("月运输趟数");
					if(StringUtils.isNotEmpty(audVisitTkVO.getTransTms())){//月运输趟数
						previewString.append(audVisitTkVO.getTransTms()+"，");
					}else{
						previewString.append("  ，");
					}
					previewString.append("扣除费用");
					if(StringUtils.isNotEmpty(audVisitTkVO.getTransFee())){//费用
						previewString.append(audVisitTkVO.getTransFee()+"，");
					}else{
						previewString.append("  ，");
					}
					previewString.append("月净收入");
					if(StringUtils.isNotEmpty(audVisitTkVO.getPurInc())){//月净收入
						previewString.append(audVisitTkVO.getPurInc()+"。");
					}else{
						previewString.append("  。");
					}
					previewString.append("其他信息");
					if(StringUtils.isNotEmpty(audVisitTkVO.getOtherInfo())){//其他信息
						previewString.append(audVisitTkVO.getOtherInfo()+"。");
					}else{
						previewString.append("  。");
					}
					
					
				}
			}
		}
		return previewString.toString();
	}
}
